#include "controllerview.h"
#include <QQmlEngine>
#include <QSystemTrayIcon>
#include <QMenu>
#include <QAction>
#include <QDebug>
#include <QQmlContext>
#include "windows.h"

ControllerView::ControllerView(QQuickView *parent):QQuickView(parent)
{

    //setFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint| Qt::Window);
    setFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
    setColor(Qt::transparent);
    setResizeMode(QQuickView::SizeRootObjectToView);
    setWidth(400);
    setHeight(100);
//    setMinimumHeight(450);
//    setMinimumWidth(450);
//    setMaximumWidth(450);
//    setMaximumHeight(450);

    contrHelper = new DDFramelessHelper(this);
    contrHelper->activateOnQmlWidget(this);
    contrHelper->setTitleHeight(100);


    setIcon(QIcon(":/images/360logo.ico"));
    setTitle("中国必印网文件自动下载器 V1.0");
}

/**
 * @brief ControllerView::setSourceAndRegsiterObj
 * @param url
 * @param regsiter
 * 注册视图QML方法
 */
void ControllerView::setSourceAndRegsiterObj(const QUrl &url, bool regsiter){
    if(regsiter){
        rootContext()->setContextProperty("contrCtrl", this);
        setSource(url);

        HWND hd=GetDesktopWindow();        //得到桌面窗口
        hd=GetWindow(hd,GW_CHILD);        //得到屏幕上第一个子窗口
        TCHAR windowText[255];
        int num=1;
        QString CdrTitles = "";
        while(hd!=NULL)                    //循环得到所有的子窗口
        {
           GetWindowText(hd,windowText,255);
           if(QString::fromWCharArray(windowText).contains("CorelDRAW",Qt::CaseSensitive) == true){
               CdrTitles = QString::fromWCharArray(windowText);
               qDebug() << CdrTitles;
               break;
           }
            hd=GetNextWindow(hd,GW_HWNDNEXT);
        }

    }
}


